package org.example;

import com.alibaba.fastjson.JSON;
import com.entity.User;
import com.mapper.UserMapper;
import com.util.ResponseUtil;
import com.util.SqlSessionUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "tbUser", value = "/user/list")
public class TestUserServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        SqlSession sqlSession = SqlSessionUtil.getSqlSession();

        // if
        {
            Map<String, String> param = new HashMap<String, String>();
            param.put("name", "哪吒");
//                User user = sqlSession.selectOne("com.mapper.UserMapper.ifDemo", param);

            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            User user = userMapper.ifDemo(param);

            ResponseUtil.doPrint(response, JSON.toJSONString(JSON.toJSONString(user)));
        }
    }

    public void destroy() {
    }
}